<template>
  <div class="app-container">
    <el-dialog title="修改刮刮卡信息" :visible.sync="dialogconUp" center @close="close">
      <el-form :model="accuseitem" ref="presentlist" label-width="120px" class="demo-presentlist">
        <el-form-item label="归属点" prop="acptsiteid">
          <el-select v-model="accuseitem.tabCode.codeName" placeholder="请选择">
            <el-option label="a营业厅" value="36"></el-option>
            <el-option label="飞黄腾达" value="43"></el-option>
            <el-option label="望子成龙" value="44"></el-option>
            <el-option label="春天来了" value="45"></el-option>
            <el-option label="深野留京紫" value="46"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="奖品等级" prop="prizelevel">
          <el-select v-model="accuseitem.prizelevel" placeholder="请选择">
            <el-option label="一等奖" value="1"></el-option>
            <el-option label="二等奖" value="2"></el-option>
            <el-option label="三等奖" value="3"></el-option>
            <el-option label="四等奖" value="4"></el-option>
            <el-option label="五等奖" value="5"></el-option>
            <el-option label="六等奖" value="6"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生效时间" prop="begintime">
          <el-date-picker
              v-model="accuseitem.begintime"
              type="datetime"
              placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="失效时间" prop="endtime">
          <el-date-picker
              v-model="accuseitem.endtime"
              type="datetime"
              placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" style="width: 400px" prop="remarks">
          <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="accuseitem.remarks">
          </el-input>
        </el-form-item>
        <el-form-item style="margin-top: 20px">
          <el-button type="primary" @click="submitForm('presentlist')">修改</el-button>
          <el-button @click="resetForm('presentlist')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import gift from "@/api/gift";

export default {
  props: {
    dialogconUpdate: {
      type: Boolean,
      default: false
    },
    accuseitem: {
      giftcode: null,//礼品编码
      prizelevel: '',//礼品等级
      begintime: '',//生效时间
      endtime: '',//失效时间
      remarks: '',//备注
      tabCode: {codeName: null}
    }
  },
  data() {
    return {
      dialogconUp: false,
      dialogImageUrl: '',
      presentlist: {
        giftcode: '',//礼品编码
        acptsiteid: '',//归属点
        prizelevel: '',//礼品等级
        begintime: '',//生效时间
        endtime: '',//失效时间
        remarks: '',//备注
      }
    };
  },
  methods: {
    close() {
      this.$emit("update:dialogconUpdate", false)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        this.presentlist.giftcode = this.accuseitem.giftcode;
        this.presentlist.acptsiteid = this.accuseitem.tabCode.codeName
        this.presentlist.prizelevel = this.accuseitem.prizelevel;
        this.presentlist.begintime = this.accuseitem.begintime;
        this.presentlist.endtime = this.accuseitem.endtime;
        this.presentlist.remarks = this.accuseitem.remarks;
        console.log(this.presentlist)
        gift.updates(this.presentlist).then(res => {
          console.log(res)
          if (res.data == true) {
            this.$message({
              type: 'success',
              message: '修改成功!',
            });
          } else {
            this.$message({
              type: 'defeated',
              message: '修改失败!',
            });
          }
        })
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  watch: {
    dialogconUpdate: {
      handler(newValue, oldValue) {
        this.dialogconUp = newValue;
        console.log(newValue, oldValue);
      }
    }
  }
}
</script>
